/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.chipchip.controller;

import com.chipchip.objects.CCMessage;
import com.chipchip.objects.Command;
import io.netty.channel.ChannelHandlerContext;
import java.io.IOException;
import zme.api.exception.ZingMeApiException;

/**
 *
 * @author Tri
 */
public class GlobalNetworkHandler {
    private GlobalLogicHandler logicHandler;
    private static GlobalNetworkHandler _instance = null;
    public ChannelHandlerContext ctx;
    private GlobalNetworkHandler() {
        logicHandler = GlobalLogicHandler.sharedInstance();
    }
    
    public static GlobalNetworkHandler sharedInstance() {
        if (_instance == null) {
            _instance = new GlobalNetworkHandler();
        }
        return _instance;
    }
    
    public void onMessage(CCMessage msg) throws IOException, ZingMeApiException {
        logicHandler.ctx = this.ctx;
        System.out.println("Received Message " + msg.id);
        switch(msg.id) {
            case Command.BUY_ITEM_STATUS: 
            {    
                break;
            }
            case Command.COMPLETE_STORY:
            {
                break;
            }
            case Command.FRIENDS_LIST:
            {
                break;
            }
            case Command.LOGIN:
            {
                logicHandler.getUserInfoFromSignedRequest("");
                System.out.println("Lay danh sach tu DB");
                logicHandler.testDatabase();
                break;
            }
            case Command.MAPS_LIST:
            {
                break;
            }
            case Command.MAP_RESULT:
            {
                break;
            }
            case Command.MAP_SELECT:
            {
                break;
            }
            case Command.UPDATE_USER_INFO:
            {
                break;
            }
            case Command.USER_INFO:
            {
                String signedRequest = msg.readString();
                logicHandler.getUserInfoFromSignedRequest(signedRequest);
                break;
            }
            case Command.USER_MAPS_LIST:
            {
                
                break;
            }
            case Command.USER_MAP_INFO:
            {
                
                break;
            }
            case Command.USER_MAP_RESULT:
            {
                break;
            }
            default:
                System.out.println("INVALID MESSAGE");
                break;
        }
    }
}
